
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;


/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Marco Angelo
 */
public class Connector {
    private static final String SERVER_ERROR = "Server Connection Error";
    public static String user = "root";
    public static String password = "p@ssword";
    public static String url = "jdbc:mysql://localhost:3306/medmartpayroll_db";
    private static Connection connection;

    public static Connection get() {

        try {
            if (connection == null || connection.isClosed()) {
                Class.forName("com.mysql.jdbc.Driver");
                connection = DriverManager.getConnection(url, user, password);

            }
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(Connector.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex.getMessage(), SERVER_ERROR, JOptionPane.ERROR_MESSAGE);
        }

        return connection;
    }

    public static void close() {

        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(Connector.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

}
